package com.ruoyi.project.system.defaultaction.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.defaultaction.domain.DefaultAction;
import com.ruoyi.project.system.defaultaction.service.IDefaultActionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 默认角色Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@Controller
@RequestMapping("/system/defaultaction")
public class DefaultActionController extends BaseController
{
    private String prefix = "system/defaultaction";

    @Autowired
    private IDefaultActionService defaultActionService;

    @RequiresPermissions("system:defaultaction:view")
    @GetMapping()
    public String defaultaction()
    {
        return prefix + "/defaultaction";
    }

    /**
     * 查询默认角色列表
     */
    @RequiresPermissions("system:defaultaction:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DefaultAction defaultAction)
    {
        startPage();
        List<DefaultAction> list = defaultActionService.selectDefaultActionList(defaultAction);
        return getDataTable(list);
    }

    /**
     * 导出默认角色列表
     */
    @RequiresPermissions("system:defaultaction:export")
    @Log(title = "默认角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DefaultAction defaultAction)
    {
        List<DefaultAction> list = defaultActionService.selectDefaultActionList(defaultAction);
        ExcelUtil<DefaultAction> util = new ExcelUtil<DefaultAction>(DefaultAction.class);
        return util.exportExcel(list, "默认角色数据");
    }

    /**
     * 新增默认角色
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存默认角色
     */
    @RequiresPermissions("system:defaultaction:add")
    @Log(title = "默认角色", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DefaultAction defaultAction)
    {
        return toAjax(defaultActionService.insertDefaultAction(defaultAction));
    }

    /**
     * 修改默认角色
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DefaultAction defaultAction = defaultActionService.selectDefaultActionById(id);
        mmap.put("defaultAction", defaultAction);
        return prefix + "/edit";
    }

    /**
     * 修改保存默认角色
     */
    @RequiresPermissions("system:defaultaction:edit")
    @Log(title = "默认角色", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DefaultAction defaultAction)
    {
        return toAjax(defaultActionService.updateDefaultAction(defaultAction));
    }

    /**
     * 删除默认角色
     */
    @RequiresPermissions("system:defaultaction:remove")
    @Log(title = "默认角色", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(defaultActionService.deleteDefaultActionByIds(ids));
    }
}
